var express = require("express");
var router = express.Router();
let { user, room, NoticeModel, houserent } = require("../models/model");

router.get("/getNotice", async (req, res) => {
  let data = await NoticeModel.find();
  res.send({
    code: 200,
    data: data,
    msg: "ok",
  });
});

// 获取全部房源
router.get("/gethouserent", async (req, res) => {
  let { page, pagesize } = req.query;
  let houses = await houserent
    .find()
    .skip((page - 1) * pagesize)
    .limit(pagesize);
  res.send({
    code: 200,
    data: houses,
    msg: "houses 获取成功",
  });
});

// 详情数据
router.get("/detail", async (req, res) => {
  let { id } = req.query;
  let data = await houserent.findOne({ _id: id });
  res.send({
    code: 200,
    data,
  });
});

module.exports = router;
